<?

class Reportes_model extends CI_Model {

    public function __construct()
	{
		$this->load->database();
	}

    function prueba() {
        return $query = $this->db->get('alerta');
    }
	
	function get_all_distritos(){
		$query = $this->db->query("select distrito, count(*) as cantidad from alerta group by distrito");
		//echo $query->result_array();
		return $query->result_array();		
	}
	
	function get_all_emergencias(){
		$query = $this->db->query("select distrito, count(*) as cantidad from alerta where isEmergencia='1' group by distrito");
		//echo $query->result_array();
		return $query->result_array();		
	}
	
	function get_all_incidentes(){
		$query = $this->db->query("select distrito, count(*) as cantidad from alerta where isEmergencia='0' group by distrito");
		//echo $query->result_array();
		return $query->result_array();		
	}
	
	function get_emergencias_by_dates($fechIni,$fechFin){
		$query = $this->db->query("select distrito, count(*) as cantidad from alerta where isEmergencia='1' and fecha between '".$fechIni."' and '".$fechFin ."' group by distrito");
		//print($this->db->last_query());
		return $query->result_array();		
	}
	
	function get_tipo_emergencias($fechIni,$fechFin){
		$query = $this->db->query("select nombreTipoAlerta, count(*) as cantidad from alerta,tipoAlerta where isEmergencia='1' and fecha between '".$fechIni."' and '".$fechFin ."' and tipoAlerta.idTipoAlerta=alerta.idTipoAlerta  group by nombreTipoAlerta");
		//echo $query->result_array();
		return $query->result_array();		
	}
	
	function get_tipo_incidentes(){
		$query = $this->db->query("select nombreTipoAlerta, count(*) as cantidad from alerta,tipoAlerta where isEmergencia='0' and tipoAlerta.idTipoAlerta=alerta.idTipoAlerta  group by nombreTipoAlerta");
		//echo $query->result_array();
		return $query->result_array();		
	}

}